package com.passionfruit.web.www;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.passionfruit.common.utils.R;
import com.passionfruit.module.entity.BlogArticleTag;
import com.passionfruit.module.service.IBlogArticleTagService;
import com.xiaoleilu.hutool.convert.Convert;
import com.xiaoleilu.hutool.util.CollectionUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 
 * 
 * @author weirdor
 * @email 179946422@qq.com
 * @date 2017-11-06 20:05:14
 */
@RestController
@RequestMapping("/module/blogarticletag")
public class BlogArticleTagController {
	@Autowired
	private IBlogArticleTagService blogArticleTagService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("module:blogarticletag:list")
	public R list(@RequestParam Map<String, Object> params){
		EntityWrapper<BlogArticleTag> wrapper = new EntityWrapper<BlogArticleTag>();

		Page<BlogArticleTag> pageUtil = blogArticleTagService.selectPage(new Page<BlogArticleTag>(Convert.toInt(params.get("page")), Convert.toInt(params.get("limit"))), wrapper);
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("module:blogarticletag:info")
	public R info(@PathVariable("id") Integer id){
		BlogArticleTag blogArticleTag = blogArticleTagService.selectById(id);
		
		return R.ok().put("blogArticleTag", blogArticleTag);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("module:blogarticletag:save")
	public R save(@RequestBody BlogArticleTag blogArticleTag){
		blogArticleTagService.insert(blogArticleTag);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("module:blogarticletag:update")
	public R update(@RequestBody BlogArticleTag blogArticleTag){
		blogArticleTagService.updateById(blogArticleTag);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("module:blogarticletag:delete")
	public R delete(@RequestBody Integer[] ids){
		blogArticleTagService.deleteById(CollectionUtil.newArrayList(ids));
		
		return R.ok();
	}
	
}
